/* Copyright 2021 Kerim Yalcin
**
**   Licensed under the Apache License, Version 2.0 (the "License");
**   you may not use this file except in compliance with the License.
**   You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
**   Unless required by applicable law or agreed to in writing, software
**   distributed under the License is distributed on an "AS IS" BASIS,
**   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
**   See the License for the specific language governing permissions and
**   limitations under the License.
*/

#ifndef AGX_SECURITY_HEADER
#define AGX_SECURITY_HEADER

#include <windows.h>
#include <accctrl.h>

namespace Agx {

class Security {
    private:
        HANDLE mHandle;
        SE_OBJECT_TYPE mObjectType;
        SECURITY_INFORMATION mSecurityInformationType;

        PSID* mSID_Owner_toRetrieve;
        PSID* mSID_Group_toRetrieve;
        PACL* mDACL_toRetrieve;
        PACL* mSACL_toRetrieve;
        PSECURITY_DESCRIPTOR* mSecurityDescriptor_toRetrieve;

        PSID mSID_Owner_toApply;
        PSID mSID_Group_toApply;
        PACL mDACL_toApply;
        PACL mSACL_toApply;
        PSECURITY_DESCRIPTOR mSecurityDescriptor_toApply;

    public:
        Security();

        void set_Handle(HANDLE pHandle);
        HANDLE get_Handle();

        void set_ObjectType_toUnknown();
        void set_ObjectType_toFile();
        void set_ObjectType_toService();
        void set_ObjectType_toPrinter();
        void set_ObjectType_toRegistryKey();
        void set_ObjectType_toNetworkShare();
        void set_ObjectType_toKernel();
        void set_ObjectType_toWindow();
        void set_ObjectType_toDirectoryService();
        void set_ObjectType_toDirectoryService_all();
        void set_ObjectType_toProviderDefined();
        void set_ObjectType_toWMI();
        void set_ObjectType_toRegistryEntry32Key_underWOW64();
        void set_ObjectType_toRegistryEntry64Key_underWOW64();
        const SE_OBJECT_TYPE& get_ObjectType() const;

        void enable_SecurityInformationType_DACL();
        void enable_SecurityInformatinoType_PrimaryGroupIdentifier();
        void enable_SecurityInformatinoType_MandatoryIntegrityLabel();
        void enable_SecurityInformatinoType_OwnerIdentifier();
        void enable_SecurityInformatinoType_DACL_protected();
        void enable_SecurityInformatinoType_SACL_protected();
        void enable_SecurityInformatinoType_SACL();
        void enable_SecurityInformatinoType_DACL_unprotected();
        void enable_SecurityInformatinoType_SACL_unprotected();
        void disable_SecurityInformationType_DACL();
        void disable_SecurityInformatinoType_PrimaryGroupIdentifier();
        void disable_SecurityInformatinoType_MandatoryIntegrityLabel();
        void disable_SecurityInformatinoType_OwnerIdentifier();
        void disable_SecurityInformatinoType_DACL_protected();
        void disable_SecurityInformatinoType_SACL_protected();
        void disable_SecurityInformatinoType_SACL();
        void disable_SecurityInformatinoType_DACL_unprotected();
        void disable_SecurityInformatinoType_SACL_unprotected();
        const SECURITY_INFORMATION& get_SecurityInformationType() const;

        void retrieve();
        void apply();
};

}

#endif